package com.itqf.studentinfo.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itqf.studentinfo.entity.Student;
import com.itqf.studentinfo.mapper.StudentMapper;
import com.itqf.studentinfo.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @program: studentinfo
 * @description:
 * @author: Mr.徐
 * @create: 2019-12-05 10:29
 * <p>
 * 人有生老三千疾,唯有相思不可以丶
 */
@Service
public class StudentServiceimpl implements StudentService {
    @Autowired
    private StudentMapper studentMapper;
    @Override
    public PageInfo<Student> queryAll(int currentPage,int pageSize) {
        PageHelper.startPage(currentPage,pageSize);
        List<Student> list = studentMapper.queryAll();
        PageInfo<Student>pd=new PageInfo<>(list);
        return pd;
    }

    @Override
    public void delete(Integer id) {
        int i = studentMapper.deleteById(id);

    }

    @Override
    public int add(Student student) {
        System.err.println(student);
        int i = studentMapper.insertSelective(student);
        return i;
    }

    @Override
    public PageInfo<Student> find(int currentPage,int pageSize,String name) {
        PageHelper.startPage(currentPage,pageSize);
        List<Student> studentList = studentMapper.selectbyName(name);
        PageInfo<Student> pd =new PageInfo<>(studentList);
        return pd;
    }

    @Override
    public Student findOne(int id) {
        Student student = new Student();
        student.setId(id);
        return studentMapper.selectOne(student);
    }

    @Override
    public int updatestu(Student student) {
        return studentMapper.updateStudent(student);
    }

}
